import React, { useMemo } from 'react';
import CommonApplyPage from './common';
import { getSearchName } from '@/utils';
import { applyType } from '@/constants';
import { useSelector } from 'react-redux';
import { DOCUMENT_TYPE_LIST } from '../declare/constants';


const OfficialApply: React.FC<any> = (props) => {
  const { userInfo } = useSelector((state: any) => ({
    userInfo: state.common.userInfo
  }));

  const setProps = (user) => {
    const searchApplyType = getSearchName('applyType');
    switch (searchApplyType) {
      case applyType.ONLINE_DOCUMENT_APPLY:
        return {
          applyType: searchApplyType,
          // 创建时默认数据
          defaultFormValues: {
            orgId: { 'value': user?.orgId, 'text': user?.orgName, 'type': 1 }, // 1 部门, 2 人
            documentType: { text: DOCUMENT_TYPE_LIST[0].label, value: DOCUMENT_TYPE_LIST[0].value },
            documentName: `${user?.orgName || ''}党政联席会会议纪要`,
            ccUserList: [{ text: user?.userName, value: user?.userId, type: 2 }], // 1 部门, 2 人
            isInvolvePerformance: { value: 0, text: '否' }
          }
        };
      case applyType.STUDENT_LABOUR_APPLY:
      default:
        return {};
    }
  };

  const setPropsMemo = useMemo(() => setProps(userInfo), [userInfo]);

  return (
    <CommonApplyPage
      {...props}
      {...setPropsMemo}
    />
  );
};
export default OfficialApply;